#include "mt0.h"
#include "result.h"
#include <string>
using namespace std;

regex_base* mt0::copy() const
{
     mt0* p = new mt0();
     p->what = what ? what->copy() : 0;
     return p;
}

match_result mt0::match(const std::string& s) const
{
     size_t length=0;

     string look(s.begin(),s.end());

     for(;;)
     {
          match_result mr = what->match(look);
          if(mr.get_matched())
          {
               length+=mr.get_length();

               if(length!=s.length())
                    look = string(s.begin()+length,s.end());
               else
                    return match_result(true,length);

               continue;
          }
          else
          {
               return match_result(true,length);
          }
     }
}

mt0::mt0(const regex_base& r)
{
     what = r.copy();
}

mt0& mt0::operator=(const mt0& m)
{
     if(what!=0) {delete what;}
     what = m.what->copy();
     return *this;
}
